package com.book.util;

import lombok.Data;

/**
 * @author SuperYu
 * @date 2024/4/19
 * <p>
 * 200: 代表成功
 * 40X: 代表访问错误
 * 50X: 代表失败
 */
@Data
public class JsonResult<T> {
    private Integer status;
    private String message;
    private T data;

    public JsonResult() {
    }

    public JsonResult(Integer status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public static <T> JsonResult<T> build(Integer status, String message, T data) {
        return new JsonResult<T>(status, message, data);
    }

    public static <T> JsonResult<T> ok(Integer status, T data) {
        return new JsonResult<T>(200, "请求成功", data);
    }

    public static <T> JsonResult<T> error(Integer status, T data) {
        return new JsonResult<T>(500, "请求失败", data);
    }
}
